import { getAppsData } from '~/server/plugins/apps'

export default defineEventHandler(async (event) => {
  const query = getQuery(event)
  const slug = query.slug as string

  if (!slug) {
    throw createError({
      statusCode: 400,
      message: 'Slug parameter is required'
    })
  }

  try {
    // 从内存中获取所有应用数据
    const allApps = getAppsData()
    
    // 直接在所有应用中查找匹配的应用
    const foundApp = allApps.find(app => app.slug === slug)
    
    return {
      app: foundApp || null
    }

  } catch (error) {
    console.error('Error finding app:', error)
    throw createError({
      statusCode: 500,
      message: 'Failed to find app'
    })
  }
}) 